@extends('develop.layoutEdit')

@section('css')
    <style>
        .layer-go-back{
            display:none;
        }
    </style>
@endsection

@section('title')

    <li class="cur">
        <span>百度设置</span>
    </li>

@endsection

@section('content')

    <input type="hidden" name="function_id" id="function_id" value="{{ $function_id or ''}}">

    <div class="form-group">
        <label class="col-sm-3 control-label" for="baidu_js">百度地图接口JS地址：</label>
        <div class="col-sm-5">
            <input type="text" placeholder="请输入百度地图接口JS地址"  name="baidu_js" id="baidu_js" value="{{$configure['baidu_js'] or ''}}" class="form-control">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label">是否开启百度统计：</label>
        <div class="col-sm-9">

            <div class="layui-form">
                <input type="radio" name="is_baidu_stat"  class="is_baidu_stat" lay-filter="check" value="1" title="关闭" checked>
                <input type="radio" name="is_baidu_stat"  class="is_baidu_stat" lay-filter="check" value="2" title="开启" @if(isset($configure['is_baidu_stat']) && $configure['is_baidu_stat'] == 2) checked @endif>
            </div>

        </div>
    </div>

    <div class="form-group " id="census" @if(isset($configure['is_baidu_stat']) && $configure['is_baidu_stat'] == 2) style="display: block" @else style="display: none" @endif>
        <label class="col-sm-3 control-label" for="census_code" style="padding-left: 0px;"><span class="red pr5">*</span> 百度统计代码：</label>
        <div class="col-sm-6">
            <textarea name="census_code" class="form-control" id="census_code" rows="10"  placeholder="请输入百度统计代码">{{$configure['census_code'] or ''}}</textarea>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"></label>
        <div class="col-sm-9">
            <input type="button"  value="保存" onclick="func.edit();" class="btn btn-success" >
        </div>
    </div>


@endsection

@section('js')
    <script>

        layui.use(['form'], function(){

            var form = layui.form();

            form.on('radio(check)', function(data){
                var value = data.value;
                if ( value == 1 ) {
                    $('#census').hide();
                } else {
                    $('#census').show();
                }
            });

        });

        var func = {

            function_id:{{ $function_id or 0}},

            edit:function(){

                var function_id = $("#function_id").val() ;
                var baidu_js = $('#baidu_js').val() ;
                var is_baidu_stat = $('input[name="is_baidu_stat"]:checked').val();
                var census_code = $('#census_code').val() ;
                var message_log = '' ;

                var configure ={ } ;
                configure.baidu_js = baidu_js ;
                configure.is_baidu_stat = is_baidu_stat ;
                configure.function_id = function_id ;

                if ( configure.is_baidu_stat == 2 ) {
                    configure.census_code = census_code;
                }

                //参数判断
                if ( E.isEmpty(configure.function_id ) || !E.isInt( configure.function_id ) ) {
                    message_log += '参数错误<br/>' ;
                }

                if ( configure.is_baidu_stat == 2 ) {
                    if ( E.isEmpty(configure.census_code) ) {
                        message_log += '请输入百度统计代码<br/>' ;
                    }
                }

                if ( message_log ) {
                    layer.alert( message_log , { icon:2 });
                    return false ;
                }

                layer.confirm("您确认保存该设置吗？",{icon:3,offset:'50px'}, function ( index ){
                    layer.close( index );
                    E.ajax( {
                        type:'get',
                        url: '/lar/develop/function/store/'+func.function_id,
                        data: configure,
                        dataType:'json',
                        // 返回值判断
                        success: function ( obj ){

                            if ( obj.code == 200 ) {
                                layer.alert( obj.message , { icon: 1,time : 1500 } ) ;
                            } else {
                                layer.alert( obj.message , { icon: 2 } ) ;
                            }
                        }
                    } ) ;
                });

            }

        };

    </script>
@endsection
